﻿using Lis.BLL;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.Mvc;

namespace Lis.Web.Controllers
{
    public class BookInfoController : Controller
    {

        public BookInfoService BookInfoService { get; set; }

        // GET: BookInfo
        public ActionResult Index()
        {
            return View();
        }

        #region 01，展示所有的图书信息+JsonResult ShowAllBook()
        /// <summary>
        /// 展示所有的图书信息
        /// </summary>
        /// <returns></returns>
        public JsonResult ShowAllBook()
        {
            int pageInde = Request["page"] == null ? 1 : int.Parse(Request["page"]);
            int pageSize = Request["rows"] == null ? 1 : int.Parse(Request["rows"]);
            int totalCount;
            var bookList = BookInfoService.GetPageEntities<string>(pageSize, pageInde, out totalCount, true, u => u.SSH != null || u.SSH != "", u => u.CBRQ).ToList();
            var temp = from u in bookList
                       select new
                       {
                           Id = u.KZH,
                           Title = u.ZTM,
                           Author=u.ZRZ,
                           SearchCode=u.SSH,
                           ISBN=u.ISBN,
                           Publish=u.CBS,
                           PublishDate=u.CBRQ
                       };
            //客户端就是遍历rows  jq easy-ui就是遍历rows
            return Json(new { rows = temp, total = totalCount }, JsonRequestBehavior.AllowGet);
        } 
        #endregion
    }
}